<template>
  <Card>
    <Row type="flex">
      <Col span="8" order="1">
      <marvels-viewer :data="viewerData" :attachMents="attachMents" :fileParam="fileParam" :isScroll="isScroll" @initViewer="initViewer"></marvels-viewer>
      </Col>
      <Col span="16" order="2">
      <Form ref="loanInfoForm" :model="loanInfoForm" :rules="loanInfoFormRules" :label-width="120" inline>
        <Row>
          <Row style="float:right">
            <Button type="info" @click="submitconfig">提交</Button>&nbsp;&nbsp;&nbsp;
            <Button type="error" @click="chargeBackFont">退回</Button>
          </Row>
        </Row>
        <!-- 提交 -->
        <Modal v-model="submitWhy" title="提交说明">
          <td style="text-align: -webkit-center;vertical-align:middle">
            请输入处理意见
          </td>
          <td>
            <textarea v-model="submitOpinion" style="height:90%;" cols="50" rows="6" placeholder="请输入处理意见......."></textarea>
          </td>
          <Row slot="footer">
            <Button type="error" size="large" @click="submitReasonWhy">提交</Button>
            <Button type="primary" size="large" @click="submitWhy=false">关闭</Button>
          </Row>
        </Modal>
        <!-- 退回 -->
        <Modal title="退回说明" v-model="chargeBackModal">
          <form id="chargeForm">
            <table cellspacing="0" border="1" bordercolor="#000000" style="border:darkgrey;margin-left: 2%; margin-right: 2%;">
              <tr>
                <td style="text-align: -webkit-center;">
                  退回原因
                </td>
                <td>
                  <CheckboxGroup v-if="opinionTypes && opinionTypes.length" v-model="chargebackRes" style="margin-left: 30px;">
                    <Checkbox v-for="item in opinionTypes" :label='item.value' :key="item.value">
                      <span>{{item.label}}</span>
                    </Checkbox>
                  </CheckboxGroup>
                </td>
              </tr>
              <tr>
                <td style="text-align: -webkit-center;">
                  退单原因说明
                </td>
                <td>
                  <textarea v-model="chargebackDesc" style="height:90%;" cols="50" rows="6" placeholder="请输入退单原因描述......."></textarea>
                </td>
              </tr>
            </table>
          </form>
          <div slot="footer">
            <Button type="error" size="large" @click="exeChargeBack">退回</Button>
            <Button type="primary" size="large" @click="resetForm('chargeForm')">重置</Button>
            <Button type="primary" size="large" @click="chargeBackModal=false">关闭</Button>
          </div>
        </Modal>
        <customer-info-form :taskParams='taskParams'></customer-info-form>
        <loan-info-form :taskParams='taskParams2'></loan-info-form>
      </Form>
      </Col>
    </Row>
  </Card>
</template>

<script>
import marvelsViewer from '../../components/marvels-viewer.vue'
import attachmentTypeData from '../../components/attachment-type-data.js'
import customerInfoForm from '../task-processing/customerInfoForm.vue'
import loanInfoForm from '../task-processing/loanInfoForm.vue'

export default {
  name: 'credit-approve-front',
  components: {
    marvelsViewer,
    customerInfoForm,
    loanInfoForm
  },
  data () {
    return {
      baseUrl: this.$appContext.marvels_core_approve,
      $ajax: null,
      isScroll: true,
      submitWhy: false, // 提交说明框
      submitOpinion: null, // 提交原因
      chargeBackModal: false, // 退单提示框
      chargebackRes: [], // 退回原因
      opinionTypes: [],
      chargebackDesc: '', // 退回原因描述
      taskParams: {
        curLoanId: this.$route.query.loanId,
        custCardNo: this.$route.query.custCardNo,
        isModal: false,
        customerInfo: true,
        isLoad: true,
        nodeCode: 'woChecking',
        type: this.$route.query.type
      },
      taskParams2: {
        curLoanId: this.$route.query.loanId,
        custCardNo: this.$route.query.custCardNo,
        isModal: false,
        loanInfo: true,
        isLoad: true,
        type: this.$route.query.type
      },
      params: {
        loanId: ''
      },
      viewerData: [],
      fileParam: {
        url: this.$appContext.marvels_core_approve + '/approve/credit/report/service/uploadFile?loanId=' + this.$route.query.loanId + '&atmtTypeName=' + marvelsViewer.atmtTypeName + '&AtmtType=' + marvelsViewer.AtmtType,
        isShow: true
      },
      attachMents: [],

      loanInfoForm: {// 贷款信息
        principalAmt: null,
        applyTerms: null,
        productTypeName: null,
        productCode: null,
        purposeCode: null,
        receiveBankName: null,
        receiveAcctName: null,
        receiveAcctNo: null,
        paymentBankName: null,
        paymentAcctName: null,
        paymentAcctNo: null,
        insurancePolicy: {// 保单信息
          insuranceCpyCode: null,
          insuranceNum: null,
          insuranceName: null,
          insuranceTypeCode: null,
          lifeInsuranceTypeCode: null,
          insuranceEftDate: null,
          insuranceAmount: null,
          insuranceStatus: null,
          insuranceYears: null,
          additionalInsuranceNum: null,
          insurancePayTypeCode: null,
          insuranceYearAmount: null,
          insuranceTotalTerms: null,
          insurancePayedTerms: null,
          policyholderChanged: 0,
          insuranceExistLoan: 0
        },
        insuranceCheck: {// 保单核录信息
          screenCaptureCheck: null,
          screenCaptureRemark: null,
          phoneCheckResult: null,
          phoneCheckRemark: null,
          policyDisbursementsStatus: null,
          recently3YOffpayStatus: null,
          lastPayDate: null,
          lastPayAmount: null,
          recentlyYChangePayType: null,
          recordFullStatus: null,
          recordFullRemark: null,
          quizStatus: null,
          selfPolicy: null,
          otherQuestion: null,
          otherQuestionRemark: null
        }
      },
      loanInfoFormRules: {
        purposeCode: [{
          required: true,
          message: '借款用途不能为空',
          trigger: 'blur'
        }],
        receiveBankName: [{
          required: true,
          message: '收款账户银行不能为空',
          trigger: 'blur'
        }],
        receiveAcctName: [{
          required: true,
          message: '收款账户名称不能为空',
          trigger: 'blur'
        }],
        receiveAcctNo: [{
          required: true,
          message: '收款账户卡号不能为空',
          trigger: 'blur'
        },
        {
          pattern: this.$util.regExpNum,
          message: '收款账户卡号不能为非数字类型',
          trigger: 'blur'
        }],
        paymentBankName: [{
          required: true,
          message: '还款账户银行不能为空',
          trigger: 'blur'
        }],
        paymentAcctName: [{
          required: true,
          message: '还款账户名称不能为空',
          trigger: 'blur'
        }],
        paymentAcctNo: [{
          required: true,
          message: '还款账户卡号不能为空',
          trigger: 'blur'
        },
        {
          pattern: this.$util.regExpNum,
          message: '还款账户卡号不能为非数字类型',
          trigger: 'blur'
        }],
        'insurancePolicy.insuranceCpyCode': [{
          required: true,
          message: '保险公司不能为空',
          trigger: 'blur'
        }],
        'insurancePolicy.additionalInsuranceNum': [{
          pattern: this.$util.regExpNum,
          message: '附加险数量不能为非数字类型',
          trigger: 'blur'
        }],
        'insurancePolicy.insuranceNum': [{
          required: true,
          message: '保单号不能为空',
          trigger: 'blur'
        }],
        'insurancePolicy.insuranceTypeCode': [{
          required: true,
          message: '保单类型不能为空',
          trigger: 'blur'
        }],
        'insurancePolicy.lifeInsuranceTypeCode': [{
          required: true,
          message: '寿险类型不能为空',
          trigger: 'blur'
        }],
        'insurancePolicy.insuranceEftDate': [{
          required: true,
          type: 'date',
          message: '保单生效日不能为空',
          trigger: 'blur'
        }],
        'insurancePolicy.insuranceAmount': [{
          required: true,
          message: '保费总额不能为空',
          trigger: 'blur'
        },
        {
          pattern: this.$util.regExpAmount,
          message: '保费总额不能为非数字类型',
          trigger: 'blur'
        }],
        'insurancePolicy.insuranceStatus': [{
          required: true,
          message: '保单状态不能为空',
          trigger: 'blur'
        }],
        'insurancePolicy.insuranceYears': [{
          required: true,
          pattern: this.$util.regExpNum,
          message: '投保年限不能为空',
          trigger: 'blur'
        }],
        'insurancePolicy.insurancePayTypeCode': [{
          required: true,
          message: '缴费方式不能为空',
          trigger: 'blur'
        }],
        'insurancePolicy.insuranceYearAmount': [{
          required: true,
          message: '年缴保费不能为空',
          trigger: 'blur'
        },
        {
          pattern: this.$util.regExpAmount,
          message: '年缴保费不能为非数字',
          trigger: 'blur'
        }],
        'insurancePolicy.insuranceTotalTerms': [{
          required: true,
          message: '应缴期数不能为空',
          trigger: 'blur'
        },
        {
          pattern: this.$util.regExpNum,
          message: '应缴期数不能为非数字',
          trigger: 'blur'
        }],
        'insurancePolicy.insurancePayedTerms': [{
          required: true,
          message: '已缴期数不能为空',
          trigger: 'blur'
        },
        {
          pattern: this.$util.regExpNum,
          message: '已缴期数不能为非数字',
          trigger: 'blur'
        }],
        'insurancePolicy.policyholderChanged': [{
          required: true,
          type: 'number',
          message: '投保人是否有变更不能为空',
          trigger: 'blur'
        }],
        'insurancePolicy.insuranceExistLoan': [{
          required: true,
          type: 'number',
          message: '保单是否存在保单贷款不能为空',
          trigger: 'blur'
        }],

        'insuranceCheck.screenCaptureCheck': [{
          required: true,
          // type:'number',
          message: '必填',
          trigger: 'blur'
        }],
        'insuranceCheck.phoneCheckResult': [{
          required: true,
          // type:'number',
          message: '必填',
          trigger: 'blur'
        }],
        'insuranceCheck.policyDisbursementsStatus': [{
          required: true,
          // type:'number',
          message: '必填',
          trigger: 'blur'
        }],
        'insuranceCheck.recently3YOffpayStatus': [{
          required: true,
          // type:'number',
          message: '必填',
          trigger: 'blur'
        }],
        'insuranceCheck.lastPayDate': [{
          required: true,
          type: 'date',
          message: '必填',
          trigger: 'blur'
        }],
        'insuranceCheck.lastPayAmount': [{
          required: true,
          message: '必填',
          trigger: 'blur'
        },
        {
          pattern: this.$util.regExpAmount,
          message: '最近一次缴费的金额不能为非数字',
          trigger: 'blur'
        }],
        'insuranceCheck.recentlyYChangePayType': [{
          required: true,
          // type:'number',
          message: '必填',
          trigger: 'blur'
        }],
        'insuranceCheck.recordFullStatus': [{
          required: true,
          // type:'number',
          message: '必填',
          trigger: 'blur'
        }],
        'insuranceCheck.quizStatus': [{
          required: true,
          // type:'number',
          message: '必填',
          trigger: 'blur'
        }],
        'insuranceCheck.selfPolicy': [{
          required: true,
          // type:'number',
          message: '必填',
          trigger: 'blur'
        }],
        'insuranceCheck.otherQuestion': [{
          required: true,
          // type:'number',
          message: '必填',
          trigger: 'blur'
        }]
      },
      selectPurposeData: [],
      columns2: [
        {
          title: '序号',
          type: 'index',
          align: 'center',
          width: 120
        },
        {
          align: 'center',
          title: '文件地址',
          key: 'fileName',
          render: function (h, params) {
            return h('a', {
              attrs: {
                href: params.row.fileLocation
              }
            }, params.row.fileName)
          }
        },
        {
          align: 'center',
          title: '文件识别结果',
          key: 'content'
        }
      ],
      recordingData: [],
      selectInsuranceCpyData: [],
      selectInsuranceTypeData: [],
      selectLifeInsuranceTypeData: [],
      selectInsuranceStatusData: [],
      selectInsurancePayTypeData: [],
      selectPolicyholderChangedData: [
        {
          code: 0,
          name: '否'
        },
        {
          code: 1,
          name: '是'
        }
      ],
      selectInsuranceExistLoanData: [
        {
          code: 0,
          name: '否'
        },
        {
          code: 1,
          name: '是'
        }
      ],
      columns3: [
        {
          align: 'center',
          title: '房产名称',
          key: 'estateName',
          render: function (h, params) {
            const vm = this
            return h('Input', {
              props: {
                type: 'text',
                value: params.row.estateName
              },
              on: {
                'on-change' (e) {
                  vm.initTempEstateDataObject(params)
                  vm.$set(vm.tempEstateData[params.index], 'estateName', e.target.value)
                }
              }
            })
          }.bind(this)
        },
        {
          align: 'center',
          title: '房产地址',
          key: 'estateAddress',
          render: function (h, params) {
            const vm = this
            return h('Input', {
              props: {
                type: 'text',
                value: params.row.estateAddress
              },
              on: {
                'on-change' (e) {
                  vm.initTempEstateDataObject(params)
                  vm.$set(vm.tempEstateData[params.index], 'estateAddress', e.target.value)
                }
              }
            })
          }.bind(this)
        },
        {
          align: 'center',
          title: '开始时间',
          key: 'estateLoanStartDate',
          render: function (h, params) {
            const vm = this
            return h('DatePicker', {
              props: {
                type: 'date',
                value: params.row.estateLoanStartDate
              },
              on: {
                'on-change' (v1, v2) {
                  // vm.estateData[params.index].estateLoanStartDate = v1;
                  vm.initTempEstateDataObject(params)
                  vm.$set(vm.tempEstateData[params.index], 'estateLoanStartDate', v1)
                }
              }
            })
          }.bind(this)
        },
        {
          align: 'center',
          title: '还款期数',
          key: 'estateLoanPaidTerms',
          render: function (h, params) {
            const vm = this
            return h('Input', {
              props: {
                type: 'text',
                value: params.row.estateLoanPaidTerms
              },
              on: {
                'on-change' (e) {
                  vm.initTempEstateDataObject(params)
                  vm.$set(vm.tempEstateData[params.index], 'estateLoanPaidTerms', e.target.value)
                }
              }
            })
          }.bind(this)
        },
        {
          align: 'center',
          title: '月还款额',
          key: 'estateLoanMthPayment',
          render: function (h, params) {
            const vm = this
            return h('Input', {
              props: {
                type: 'text',
                value: params.row.estateLoanMthPayment
              },
              on: {
                'on-change' (e) {
                  vm.initTempEstateDataObject(params)
                  vm.$set(vm.tempEstateData[params.index], 'estateLoanMthPayment', e.target.value)
                }
              }
            })
          }.bind(this)
        },
        {
          align: 'center',
          title: '贷款状态',
          key: 'estateLoanStatus',
          render: function (h, params) {
            const vm = this
            return h('Select', {
              props: {
                value: params.row.estateLoanStatus
              },
              on: {
                'on-change' (value) {
                  vm.initTempEstateDataObject(params)
                  vm.$set(vm.tempEstateData[params.index], 'estateLoanStatus', value)
                }
              }
            }, this.selectEstateLoanStatusData.map(function (item) {
              return h('Option', {
                props: {
                  value: item.code
                }
              }, item.name)
            })
            )
          }.bind(this)
        },
        {
          align: 'center',
          title: '操作',
          width: 80,
          key: 'action',
          render: (h, params) => {
            var vm = this
            // if(vm.taskParams.isModal===true){
            //     return '';
            // }else{
            return h('div', [
              h('Button', {
                props: {
                  type: 'error',
                  size: 'small'
                },
                on: {
                  click: () => {
                    // vm.tempEstateData.splice(params.index,1);
                    // vm.estateData = vm.cloneObject(vm.tempEstateData);
                    vm.delEstateRowData(params)
                  }
                }
              }, ' 删除')
            ])
          }
          // }
        }
      ],
      estateData: [ // 房产信息 表格数据
        // {
        //     estateName:'test',
        //     estateAddress:null,
        //     estateLoanStartDate:'20180501',
        //     estateLoanStatus:'0',
        //     estateLoanPaidTerms:null,
        //     estateLoanMthPayment:null
        // }
      ],
      tempEstateData: [], // 房产信息 临时表格数据
      estateEmptyRowData: { // 房产信息表格空行对象
        estateName: null,
        estateAddress: null,
        estateLoanStartDate: null,
        estateLoanStatus: null,
        estateLoanPaidTerms: null,
        estateLoanMthPayment: null
      },
      selectEstateLoanStatusData: [
        {
          code: '0',
          name: '未结清'
        },
        {
          code: '1',
          name: '已结清'
        }
      ],
      selectRadioGroup1: [
        {
          code: '0',
          name: '否'
        },
        {
          code: '1',
          name: '是'
        }
      ],
      selectRadioGroup2: [
        {
          code: '0',
          name: '无'
        },
        {
          code: '1',
          name: '有'
        }
      ]
    }
  },
  methods: {
    initpage: function () {
      // 初始化下拉列表数据
      // this.initSelectData()
    },
    // 转成影像资料树节点
    transferToMedia (arr) {
      var vm = this
      // 封装一级节点
      var rootNode = {}
      rootNode.label = '影像资料'
      rootNode.expand = true
      rootNode.children = []
      var set = new Set()
      for (var index in arr) {
        set.add(arr[index].atmtType)
      }
      // 封装二级节点
      set.forEach(function (element, sameElement, set) {
        var secondNode = {}
        secondNode.expand = true
        secondNode.children = []
        for (var index in arr) {
          if (arr[index].atmtType === element) {
            secondNode.label = arr[index].atmtTypeName
            // 封装三级节点
            var threeNode = {}
            threeNode.label = arr[index].fileName
            threeNode.src = arr[index].fileLocation
            secondNode.children.push(threeNode)
          }
        }

        rootNode.children.push(secondNode)
        vm.viewerData.push(secondNode)
      })
    },
    // 初始化下拉列表数据
    initSelectData () {
      var vm = this
      // 查询
      this.$ajax.post(this.baseUrl + 'approve/process/task_process/service/getUploadAttamentTypes', this.params.loanId).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(message)
          return
        }
        var attachmentDatas = data.data || []
        attachmentDatas.forEach(item => {
          var tData = {}
          tData.label = item.atmtTypeName
          tData.value = item.atmtType
          vm.attachMents.push(tData)
        })
      }).catch(er => {

      })
    },
    // 初始化贷款信息tab
    initLoanInfo () {
      var vm = this
      var url = this.baseUrl + 'approve/process/task_process/service/getLoanDetail/' + this.$route.query.loanId
      this.$ajax.get(url).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code !== 'success') {
          this.$Message.warning(message)
          return
        }
        vm.loanInfoForm = data.data
        if (!vm.loanInfoForm.insurancePolicy) {
          vm.loanInfoForm.insurancePolicy = {}
        }

        if (!vm.loanInfoForm.insuranceCheck) {
          vm.loanInfoForm.insuranceCheck = {}
        }
        vm.loanInfoForm.insurancePolicy.insuranceEftDate = vm.loanInfoForm.insurancePolicy.insuranceEftDate ? new Date(vm.loanInfoForm.insurancePolicy.insuranceEftDate) : ''
        vm.loanInfoForm.insuranceCheck.lastPayDate = vm.loanInfoForm.insuranceCheck.lastPayDate ? new Date(vm.loanInfoForm.insuranceCheck.lastPayDate) : ''
        // 初始化房产信息
        vm.initEstateTable()
        // 初始化录音文件列表
        if (data.data.attachmentList) {
          vm.recordingData = data.data.attachmentList
        }
      }).catch(er => {

      })
    },
    // 初始化房产信息
    initEstateTable () {
      if (this.loanInfoForm.estateList && this.loanInfoForm.estateList.length > 0) {
        this.loadEstateData()
      }
    },
    // 加载房产信息
    loadEstateData () {
      this.estateData = this.loanInfoForm.estateList
      for (var i in this.estateData) {
        this.estateData[i].estateLoanStartDate = this.$util.formatDate(this.estateData[i].estateLoanStartDate)
      }
      // 初始化临时房产数组数据
      if (this.estateData && this.estateData.length > 0) {
        this.tempEstateData = this.cloneObject(this.estateData)
      }
    },
    // 保存贷款信息
    submitForm () {
      var vm = this
      this.$refs.loanInfoForm.validate(valid => {
        if (valid) {
          this.loanInfoForm.loanId = this.$route.query.loanId
          this.estateData = this.cloneObject(this.tempEstateData)
          this.loanInfoForm.estateList = this.estateData
          var params = this.loanInfoForm
          this.$ajax.post(this.baseUrl + 'approve/process/task_process/service/saveLoanInfo', params).then(re => {
            var data = re.data
            var code = data.code
            var message = data.message
            if (code !== 'success') {
              this.$Message.warning(message)
              return
            }
            // 重新加载房产信息
            vm.loanInfoForm.estateList = data.data.estateList
            vm.loadEstateData()
            this.$Message.success(message)
          }).catch(er => {

          })
        }
      })
    },
    // 房产信息列表 动态添加一行
    addEstateDefaultEmptyRow () {
      this.estateData = this.cloneObject(this.tempEstateData)
      this.estateData.push(this.cloneObject(this.estateEmptyRowData))
    },
    // 初始化临时房产数组数据对象
    initTempEstateDataObject (params) {
      if (!this.tempEstateData[params.index]) {
        this.tempEstateData[params.index] = {}
      }
    },
    // 复制对象
    cloneObject (obj) {
      return JSON.parse(JSON.stringify(obj))
    },
    // 删除房产信息
    delEstateRowData (params) {
      var vm = this
      var config = {
        title: '提示',
        content: '是否确认删除?',
        onOk: function () {
          ;
          var formData = params.row
          if (!formData.id) { // 新增但是还未保存的房产记录
            vm.tempEstateData.splice(params.index, 1)
            vm.estateData = vm.cloneObject(vm.tempEstateData)
            return
          }
          vm.$ajax.post(vm.baseUrl + 'approve/process/task_process/service/deleteEstateInfo', formData).then(re => {
            var data = re.data
            var code = data.code
            var message = data.message
            if (code !== 'success') {
              vm.$Message.warning(message)
              return
            }
            vm.tempEstateData.splice(params.index, 1)
            vm.estateData = vm.cloneObject(vm.tempEstateData)
          }).catch(er => {

          })
        }
      }
      this.$Modal.confirm(config)
    },
    chargeBackFont () {
      var vm = this
      vm.chargeBackModal = true
      // 重新弹出form表单需重置
      vm.chargebackRes = []
      vm.chargebackDesc = ''
    },
    // 重置退回表单
    resetForm (formId) {
      var vm = this
      vm.chargebackRes = [] // 退回原因
      vm.chargebackDesc = ''
      document.getElementById(formId).reset()
    },
    exeChargeBack () {
      var vm = this
      if (vm.chargebackRes.length < 1) {
        alert('请至少选择一个退回原因')
        return
      }
      var params = {
        loanId: this.$route.query.loanId,
        backReason: vm.chargebackDesc,
        backReasonCodes: vm.chargebackRes.toString()
      }
      // 执行退单操作
      vm.$ajax.post(vm.$appContext.marvels_core_approve + '/approve/credit/report/service/chargeBack', params).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code === 'success') {
          vm.chargeBackModal = false
          vm.$Message.success('退单成功!')
          vm.$router.back()
        } else {
          vm.$Message.success(message)
        }
      }).catch(er => {

      })
      // this.$Message.info(vm.loanId + '退单成功');
    }, // 提交审批前置
    submitconfig () {
      this.submitWhy = true
    },
    submitReasonWhy () {
      var vm = this
      var params = {}
      params.backReason = this.submitModal
      params.loanId = this.$route.query.loanId
      vm.$ajax.post(vm.$appContext.marvels_core_approve + '/approve/credit/report/service/submitCirculation', params).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code === 'success' && data.data === 2) { // 保单未截屏
          this.$Message.warning('保单未截屏，请确认截屏后再提交')
          this.submitWhy = false
        } else if (code === 'success') {
          vm.submitWhy = false
          vm.$Message.success(message)
          vm.$router.back()
        } else {
          vm.$Message.success(message)
        }
        // this.submitWhy = false;
      }).catch(er => {

      })
    },
    initMediaData (data) {
      var list = []
      if (data && data.length > 0) {
        var baseSrc = this.baseUrl + 'approve/credit/intbank/service/loadAttachmentById/'
        for (var i = 0; i < data.length; i++) {
          var viewAttach = {}
          viewAttach.label = data[i].atmtTypeName
          var attachmentList = data[i].laAttachmentDTOList
          var viewList = []
          if (attachmentList && attachmentList.length > 0) {
            for (var j = 0; j < attachmentList.length; j++) {
              let label = attachmentTypeData[attachmentList[j].atmtType] + '_' + (j + 1)
              if ((attachmentList[j].atmtType === 'A' || attachmentList[j].atmtType === 'YH') && attachmentList[j].fileName !== '' && attachmentList[j].fileName !== null) {
                label = attachmentList[j].fileName
              }
              var fileName = attachmentList[j].fileName
              var fileLocation = attachmentList[j].fileLocation
              if (!fileLocation) fileLocation = ''
              if (!fileName) fileName = ''
              var aa = {
                label: label,
                src: baseSrc + attachmentList[j].id,
                type: fileLocation.substring(fileLocation.lastIndexOf('.') + 1),
                fileType: attachmentList[j].atmtType,
                url: fileLocation
              }
              viewList.push(aa)
              viewAttach.children = viewList
            }
            list.push(viewAttach)
          }
        }
      }
      this.viewerData = list
    },
    // 初始化退回原因选项
    initOpinionTypes () {
      var vm = this
      this.$ajax.post(vm.$appContext.marvels_core_approve + 'approve/process/task_process/service/getReturnReasonList').then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code === 'success') {
          // vm.opinionTypes = data.data || []
          var opinionTypesTemp = data.data || []
          opinionTypesTemp.forEach(item => {
            vm.opinionTypes.push({
              label: item.opinionTypeName,
              value: item.opinionTypeCode
            })
          })
        } else {
          vm.$Message.error(message)
        }
      }).catch(er => {

      })
    },
    // 初始化附件影像
    initViewer () {
      var vm = this
      var params = this.$route.query.loanId
      vm.$ajax.post(vm.$appContext.marvels_core_approve + 'approve/credit/report/service/getAttachmentsByViewKey?loanId=' + params).then(re => {
        var data = re.data
        var code = data.code
        var message = data.message
        if (code === 'success') {
          vm.initMediaData(data.data)
        } else {
          vm.$Message.error(message)
        }
        // this.submitWhy = false;
      }).catch(er => {

      })
    }
  },
  computed: {

  },
  mounted () {
    // if(this.estateData && this.estateData.length < 1){
    //     this.addEstateDefaultEmptyRow();
    // }
  },
  created () {
    this.$ajax = this.$util.ajax()
    this.params.loanId = this.$route.query.loanId
    this.initSelectData()
    this.initOpinionTypes()
    this.initViewer()
  },
  watch: {
    // 点击tab页签，加载数据，只加载一次
    // 'taskParams.loanInfo'(v){
    //     if(v){
    //         this.initpage();
    //     }
    // }
  },
  props: {
    // taskParams:Object
  }
}
</script>
<style scoped>
.ivu-col-span-4 .ivu-form-item-content {
  margin-left: 0px !important;
}
</style>
